/*
 * Copyright 2010-2012 Susanta Tewari. <freecode4susant@users.sourceforge.net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package test.genomemap.data;

import commons.core.MutableData;
import genomemap.data.KSA00Data;
import genomemap.data.OrganismData;
import genomemap.data.TAB08Data;
import genomemap.model.KSA00;
import genomemap.model.TAB08;

import java.util.*;

/**
 * @author Susanta Tewari
 * @history Created on Sep 3, 2012.
 */
public class OrganismTestData {

    /** Field description */
    public static final Map<String, OrganismData> dataSet = new HashMap<>();

    static {

        dataSet.put("data-1:data-2",
                    new OrganismDataImpl(1, TAB08TestData.dataSet.get("data-1"),
                                         KSA00TestData.dataSet.get("data-1")).add(2,
                                             TAB08TestData.dataSet.get("data-2"),
                                                 KSA00TestData.dataSet.get("data-2")));
    }

    /**
     * Constructs ...
     *
     */
    private OrganismTestData() {}

    /**
     * Class description
     *
     *
     * @version        Enter version here..., 12/10/09
     * @author         Susanta Tewari
     */
    private static class OrganismDataImpl implements OrganismData {

        /** Field description */
        private final Set<Integer> linkageGroups = new HashSet<>(10);

        /** Field description */
        private final Map<Integer, TAB08Data> tab08Map = new HashMap<>(10);

        /** Field description */
        private final Map<Integer, KSA00Data> ksa00Map = new HashMap<>(10);

        OrganismDataImpl(final int linkageGroup, final TAB08Data tab08Data,
                         final KSA00Data ksa00Data) {

            linkageGroups.add(linkageGroup);
            tab08Map.put(linkageGroup, tab08Data);
            ksa00Map.put(linkageGroup, ksa00Data);
        }

        OrganismDataImpl add(final int linkageGroup, final TAB08Data tab08Data,
                             final KSA00Data ksa00Data) {

            linkageGroups.add(linkageGroup);
            tab08Map.put(linkageGroup, tab08Data);
            ksa00Map.put(linkageGroup, ksa00Data);

            return this;
        }

        /**
         * Method description
         *
         *
         * @return
         */
        @Override
        public int getCloneLength() {

            final int linkageGroup = linkageGroups.iterator().next();

            return ksa00Map.get(linkageGroup).getModel().getCloneLength();
        }

        /**
         * Method description
         *
         *
         * @return
         */
        @Override
        public Set<Integer> getLinkageGroups() {
            return linkageGroups;
        }

        /**
         * Method description
         *
         *
         * @param linkageGroup
         *
         * @return
         */
        @Override
        public List<String> genes(final Integer linkageGroup) {
            return tab08Map.get(linkageGroup).getModel().getGenes();
        }

        /**
         * Method description
         *
         *
         * @param linkageGroup
         *
         * @return
         */
        @Override
        public Set<String> clones(final Integer linkageGroup) {
            return ksa00Map.get(linkageGroup).getClones();
        }

        /**
         * Method description
         *
         *
         * @param linkageGroup
         *
         * @return
         */
        @Override
        public List<String> probes(final Integer linkageGroup) {
            return ksa00Map.get(linkageGroup).getModel().getProbes();
        }

        /**
         * Method description
         *
         *
         * @param linkageGroup
         * @param probes
         *
         * @return
         */
        @Override
        public KSA00Data createKSA00Data(final Integer linkageGroup, final List<String> probes) {

            final KSA00Data data = ksa00Map.get(linkageGroup);

            if (probes == null) {
                return data;
            }

            final MutableData<KSA00, KSA00Data> mutableData = data.getMutable();

            mutableData.setModel(data.getModel().newOrder(probes));

            return mutableData.getImmutable();
        }

        /**
         * Method description
         *
         *
         * @param linkageGroup
         * @param genes
         *
         * @return
         */
        @Override
        public TAB08Data createTAB08Data(final Integer linkageGroup, final List<String> genes) {

            final TAB08Data data = tab08Map.get(linkageGroup);

            if (genes == null) {
                return data;
            }

            final MutableData<TAB08, TAB08Data> mutableData = data.getMutable();

            mutableData.setModel(data.getModel().newOrder(genes));

            return mutableData.getImmutable();
        }
    }
}
